import os
import matplotlib.pyplot as plt

from glob import glob
from collections import OrderedDict
from utils import get_json_points, get_fidtm_map_num


def show_comparisons(image_names, save_path):
    for image_name in image_names:
        image_file = os.path.join(save_path, str(image_name)+".png")
        img = plt.imread(image_file)
        plt.figure(figsize=(16, 12))
        plt.imshow(img)
        plt.axis('off')
        plt.show()



# 测试数据、方法信息

data_name = 'RGBTCC'

gt_path = "../datasets/rgbtcc/test"
gt_list = glob(os.path.join(gt_path, '*.json'))

method_results = {
    'FIDTM': f"/data/store1/nzd/mamba/prj/fidtm_tir_rgbtcc/map_{data_name}",
}

save_path = './1_visul_comparison_rgbtcc'



static = {}
for i, gt_file in enumerate(gt_list):
    # 1.获取原始数据
    gt_name = os.path.basename(gt_file)
    et_name = gt_name.replace("_GT.json", "_RGB.pt")
    
    points = get_json_points(gt_file)
    gt_num = len(points)

    et_file = os.path.join(method_results['FIDTM'], et_name)
    et_map, et_num = get_fidtm_map_num(et_file)
    
    static[et_name.split('.')[0]] = abs(gt_num - et_num)
static = OrderedDict(sorted(static.items(), key=lambda x: x[1]))



good_names = [k for k, v in static.items()][:500]

bad_names = [k for k, v in static.items()][-200:]
#good_names.reverse()
bad_names.reverse()


show_comparisons(good_names, save_path)